
#ifndef __MQTTC_H__
#define __MQTTC_H__

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @brief Topic list.
 * 
 * heatbeat:
 *      topic:/heartbeat
 *      direction: device to controller(d2c).
 * data:
 *      topic: /device/<devid>/data
 *      direction: d2c
 * cmd response:
 *      /device/<devid>/resp
 *      direction: d2c.
 * cmd request: 
 *      /device/<devid>/req
 *      direction: c2d.
 */
#define D2C_HEATBEAT  "/heartbeat"
#define D2C_RESPONSE  "/device/%s/resp"
#define C2D_REQUEST   "/device/%s/req"

typedef void (*mqttc_data_arrived_cb_t)(void *handler, const char *topic, int topic_len, uint8_t *data, int data_len);

struct mqttc_handler
{
    void *client_handler;
    void *event_handler;
    void *task_handler;
    mqttc_data_arrived_cb_t data_handler;
    uint32_t state;
};

extern void mqttc_init(struct mqttc_handler *handler, mqttc_data_arrived_cb_t data_handler, int priority);
extern int mqttc_is_connected(struct mqttc_handler *handler);
extern int mqttc_is_disconnected(struct mqttc_handler *handler);
extern int mqttc_start(struct mqttc_handler *handler);
extern int mqttc_stop(struct mqttc_handler *handler);
extern int mqttc_device_subscribe(struct mqttc_handler *handler, const char *device);
extern int mqttc_device_unsubscribe(struct mqttc_handler *handler, const char *device);

extern int mqttc_device_publish_request(struct mqttc_handler *handler, const char *device, const char *data);
extern int mqttc_device_publish_led_req(struct mqttc_handler *handler, const char *device, int led);
extern int mqttc_device_publish_data(struct mqttc_handler *handler, const char *data);

#ifdef __cplusplus
}
#endif

#endif